package cn.tedu.carehome.foundation.controller;

import cn.tedu.carehome.foundation.pojo.dto.GoodlistAddNewDTO;
import cn.tedu.carehome.foundation.pojo.dto.GoodlistUpdateDTO;
import cn.tedu.carehome.foundation.pojo.vo.GoodlistListItemVO;
import cn.tedu.carehome.foundation.pojo.vo.GoodlistStandardVO;
import cn.tedu.carehome.foundation.pojo.vo.OlderListItemVO;
import cn.tedu.carehome.foundation.restful.JsonPage;
import cn.tedu.carehome.foundation.restful.WebConsts;
import cn.tedu.carehome.foundation.service.IGoodlistService;
import cn.tedu.carehome.foundation.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/goodlist")
@Slf4j
@Api(tags = "健康信息管理")
@Valid
public class GoodlistController {
    @Autowired
    private IGoodlistService goodlistService;

    @PostMapping("/add-new")
    @ApiOperation("添加健康管理信息")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@RequestBody GoodlistAddNewDTO goodlistAddNewDTO) {
        log.debug("开始处理【健康管理信息】的请求，参数：{}", goodlistAddNewDTO);
        goodlistService.addNew(goodlistAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据id删除病例信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "病例ID", required = true, example = "3", dataType = "long")
    public JsonResult<Void> delete(@Range(min = 1, max = 1000000, message = "删除信息失败，病例id非法")
                                   @PathVariable Long id) {
        log.debug("开始处理【根据id删除病例信息】的请求，参数：{}", id);
        goodlistService.deleteById(id);
        return JsonResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("查询病例信息列表")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<GoodlistListItemVO>> list() {
        log.debug("开始处理【查询病例信息列表】的请求，无参数");
        List<GoodlistListItemVO> list = goodlistService.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/list-limit")
    public JsonResult<List<GoodlistListItemVO>> listLimit(String content) {
        log.debug("开始处理【分页查询老人健康信息列表】的请求，页数：{}, 显示数量：{}, 查询的内容：{}", content);
        List<GoodlistListItemVO> listLimit = goodlistService.listLimit(content);
        return JsonResult.ok(listLimit);
    }
}
